﻿// -----------------------------------------------------------------------
// <copyright file="ThanNhanServices.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

using System.Windows.Forms;
using ASS.BUS.DTO;
using ASS.DAO;

namespace ASS.BUS.Services
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class ThanNhanServices
    {
        public bool Add(ThanNhanBenhNhan thanNhan)
        {
            bool addSuccsess = false;
            using (var db = new DataContext())
            {
                try
                {
                    db.ThanNhanBenhNhans.Add(thanNhan);
                    db.SaveChanges();
                    addSuccsess = true;
                }
                catch (Exception ex)
                {
                    addSuccsess = false;
                    MessageBox.Show(ex.Message);
                }
            }
            return addSuccsess;
        }

        public ThanNhanBenhNhan GetThanNhan(int maBn)
        {
            using (var db = new DataContext())
            {
                var item = db.ThanNhanBenhNhans.Single(x => x.MaBn == maBn);

                return item;
            }
        }

        public bool EditThanNhan(ThanNhanBenhNhan thanNhan)
        {
            using (var db = new DataContext())
            {
                var item = db.ThanNhanBenhNhans.Single(x => (x.MaBn == thanNhan.MaBn) &&
                                                            (x.Ten == thanNhan.Ten));
                if (item == null) return false;
                item.Ten = thanNhan.Ten;
                item.SoDienThoai = thanNhan.SoDienThoai;
                return true;
            }
        }
    }
}
